package com.ocom.webapi.controller;

import com.ocom.common.constant.AccessServiceUrl;
import com.ocom.common.constant.HumanServiceUrl;
import com.ocom.common.enums.ResultEnum;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.ResultUtil;
import com.ocom.webapi.feign.AccessClientService;
import com.ocom.webapi.service.StudentPageService;
import com.ocom.webapi.vo.CompanyVo;
import com.ocom.webapi.vo.studentpage.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

//@Slf4j
@RestController
@PreAuthorize("@pms.hasRole('ROLE_WEB')" )
public class StudentPageController {
    private final Logger log = LoggerFactory.getLogger(StudentPageController.class);
    @Autowired
    private StudentPageService studentPageService;

    @Autowired
    AccessClientService accessClientService;
    /**
     * 人员列表（StudentPage/onShow）
     * */
    @PostMapping(HumanServiceUrl.URL_StudentPageOnShow)
    public Result StudentPageOnShow(@Validated @RequestBody OnShowVo onShowVo){
        log.info("人员列表onShow,{{}}",onShowVo);
        return studentPageService.StudentPageOnShow(onShowVo);
    }

    /**
     * 人员信息（StudentPage/info）
     * */
    @GetMapping(HumanServiceUrl.URL_StudentPageInfo)
    public Result StudentPageInfo(Long comId,Long pId){
        log.info("人员信息:comId{{}},pId{{}} ",comId,pId);
        return studentPageService.StudentPageInfo(comId,pId);
    }


    /**
     * 新增人员信息（StudentPage/add）
     * */
    @PostMapping(HumanServiceUrl.URL_StudentPageAdd)
    public Result StudentPageAdd(@Validated @RequestBody AddVo addVo){
        if(true)  return ResultUtil.error(ResultEnum.Err_502);
        return studentPageService.StudentPageAdd(addVo);
    }


    /**
     * 修改人员信息（StudentPage/modify）
     * */
    @PostMapping(HumanServiceUrl.URL_StudentPageModify)
    public Result StudentPageModify(@Validated @RequestBody ModifyVo modifyVo){
        if(true)  return ResultUtil.error(ResultEnum.Err_502);
        return studentPageService.StudentPageModify(modifyVo);
    }


    /**
     * 人员删除（StudentPage/delete）
     * */
    @PostMapping(HumanServiceUrl.URL_StudentPageDelete)
    public Result StudentPageDelete(@Validated @RequestBody DeleteVo deleteVo){
        if(true)  return ResultUtil.error(ResultEnum.Err_502);
        log.info("人员删除:deleteVo{{}} ",deleteVo);
        return studentPageService.StudentPageDelete(deleteVo);

    }

    /**
     * 导入人员（StudentPage/import）
     * */
    @PostMapping(HumanServiceUrl.URL_StudentPageImport)
    public Result StudentPageImport( Long comId,String areaGroop,@RequestPart("file") MultipartFile file){
        if(true)  return ResultUtil.error(ResultEnum.Err_502);
        return  studentPageService.StudentPageImport(comId,areaGroop,file);
    }


    /**
     * 导入同住人员（StudentPage/boardersImport）
     * */
    @PostMapping(HumanServiceUrl.URL_StudentPageBoardersImporte)
    public Result StudentPageBoardersImporte( Long comId,@RequestPart("file") MultipartFile file){
        return  studentPageService.StudentPageBoardersImporte(comId,file);
    }

    /**
     * 同住人员列表（StudentPage/boardersList）
     * */
    @GetMapping(HumanServiceUrl.URL_StudentPageBoardersList)
    public Result StudentPageBoardersList( Long comId,Long pId){
        return studentPageService.StudentPageBoardersList(comId,pId);
    }
    /**
     * 新增同住人员（StudentPage/boardersAdd）
     * */
    @PostMapping(HumanServiceUrl.URL_StudentPageBoardersAdd)
    public Result StudentPageBoardersAdd(@Validated @RequestBody BoardersAddVo boardersAddVo){
        return studentPageService.StudentPageBoardersAdd(boardersAddVo);
    }


    /**
     * 删除同住人员（StudentPage/boardersDelete）
     * */
    @PostMapping(HumanServiceUrl.URL_StudentPageBoardersDelete)
    public Result StudentPageBoardersDelete(@Validated @RequestBody BoardersDeleteVo boardersDeleteVo){
        return studentPageService.StudentPageBoardersDelete(boardersDeleteVo);
    }


    @PostMapping(AccessServiceUrl.URL_getNhResult)
    public Result getNhResult( @RequestBody CompanyVo companyVo){
        Result result= accessClientService.getNhCount(companyVo.getCompanyId());
        if(result.getCode()==200){
            return ResultUtil.success(result.getData());
        }else{
            return result;
        }

    }
}
